package com.zyz.K_集合.List接口练习;

import java.util.LinkedList;
import java.util.Scanner;

/**
 * @author: vick
 * @Date: 2025/3/28
 * @Description:
 * @version: 1.0
 */
public class KTVLinkedList {
    //创建歌曲列表
    private static LinkedList<String> musicList = new LinkedList<>();

    private static Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {
        //初始化歌曲列表
        initMusicList();
        boolean flag = true;

        while (flag) {
            System.out.println("当前歌曲列表：" + musicList);
            System.out.println("-------------欢迎来到点歌系统------------");
            System.out.println("1.添加歌曲至列表");
            System.out.println("2.将歌曲置顶");
            System.out.println("3.将歌曲前移一位");
            System.out.println("4.退出");
            System.out.println("请输入操作序号：");
            int i = scanner.nextInt();
            switch (i) {
                case 1: //添加歌曲
                    addMusic();
                    break;
                case 2: //置顶
                    setTop();
                    break;
                case 3: // 将歌曲前移一位
                    setBefore();
                    break;
                case 4:
                    System.out.println("已经退出系统");
                    flag = false;
                    break;
                default:
                    System.out.println("请选择正确的功能序号");
            }
        }
    }

    //初始化歌曲列表
    private static void initMusicList() {
        musicList.add("命运");
        musicList.add("爱情转移");
        musicList.add("九万字");
        musicList.add("如果可以");
        musicList.add("当");
        musicList.add("富士山下");
    }

    /*
    * 添加歌曲
    * */
    private static void addMusic() {
        System.out.println("请输入要添加的歌曲");
        String musicName = scanner.next();
        musicList.add(musicName);
        System.out.println("已添加歌曲：" + musicName);
    }

    /*
    * 置顶
    * */
    private static void setTop() {
        System.out.println("请输入要置顶的歌曲名称：");
        String musicName = scanner.next();
        int musicIndex = musicList.indexOf(musicName);
        if (musicIndex < 0) {
            System.out.println("当前列表中没有这个歌曲");
        }else if (musicIndex == 0) {
            System.out.println("当前歌曲默认已经置顶");
        }else {
            musicList.remove(musicName);
            musicList.addFirst(musicName);
            System.out.println("已经将歌曲《"+ musicName + "》置顶");
        }
    }

    /*
    * 将歌曲前移一位
    * */
    private static void setBefore() {
        System.out.println("请输入要置前的歌曲名称：");
        String musicName = scanner.next();
        int musicIndex = musicList.indexOf(musicName);
        if (musicIndex < 0) {
            System.out.println("当前列表中没有这个歌曲");
        }else if (musicIndex == 0) {
            System.out.println("当前歌曲默认已经在最顶部");
        }else {
            musicList.remove(musicName);
            musicList.add(musicIndex - 1, musicName);
            System.out.println("已经将歌曲《"+ musicName + "》置前一位");
        }
    }
}
